package com.zhaodui.util;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import com.zhaodui.loan.entity.FxjLoanFkEntity;
import com.zhaodui.loan.entity.FxjLoanInsEntity;
import com.zhaodui.loan.entity.FxjLoanMaEntity;
import com.zhaodui.order.entity.FxjOrderLoanEntity;
import com.zhaodui.order.entity.FxjOrderMainEntity;
import com.zhaodui.order.entity.FxjOrderObjEntity;
import com.zhaodui.pl.entity.FxjPlReplanEntity;
import org.apache.log4j.Logger;
import org.jeecgframework.core.util.ApplicationContextUtil;
import org.jeecgframework.core.util.DateUtils;
import org.jeecgframework.core.util.ResourceUtil;
import org.jeecgframework.core.util.StringUtil;
import org.jeecgframework.web.system.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import javax.validation.Validator;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
public class printUtil {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(printUtil.class);
	public static boolean printfile(String filePath){
		boolean returnFlg = false;
		ComThread.InitSTA();
		ActiveXComponent xl = new ActiveXComponent("Excel.Application");
		try {

			// 不打开文档
			Dispatch.put(xl, "Visible", new Variant(true));
			Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
			// win下路径处理(把根目录前的斜杠删掉)
			filePath = filePath.replace("/E:/","E:/");
			// 判断文件是否存在
			boolean fileExistFlg = fileExist(filePath);
			if (fileExistFlg) {
				Dispatch excel=Dispatch.call(workbooks,"Open",filePath).toDispatch();
				// 开始打印
				Dispatch.get(excel,"PrintOut");

				returnFlg = true;
				//关闭文档
               Dispatch.call(excel, "Close", new Variant(true));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			// 始终释放资源
			xl.invoke("Quit", new Variant[] {});
			ComThread.Release();
		}
		return returnFlg;
	}
	/**
	 * 判断文件是否存在.
	 * @param filePath  文件路径
	 * @return
	 */
	private static boolean fileExist(String filePath) {
		boolean flag = false;
		try {
			File file = new File(filePath);
			flag = file.exists();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return flag;
	}
}
